package com.justech.eat.service.impl;

import com.justech.eat.entity.OrderLog;
import com.justech.eat.mapper.mysql.OrderLogMapper;
import com.justech.eat.repository.OrderLogRepository;
import com.justech.eat.service.OrderLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class OrderLogServiceImp implements OrderLogService {
    @Autowired
    OrderLogMapper OrderLogMapper;

    @Autowired
    OrderLogRepository orderLogRepository;

    @Override
    public void add(OrderLog orderLog) {
        OrderLogMapper.add(orderLog);
    }

    @Override
    public void delete(int id) {
        OrderLogMapper.deleteById(id);
    }

    @Override
    public void update(int id, long orderId, long orderDetailId, int type, String doType) {
        OrderLog orderLog = OrderLogMapper.queryById(id);
        orderLog.setOrderId(orderId);
        orderLog.setOrderDetailId(orderDetailId);
        orderLog.setType(type);
        orderLog.setDoType(doType);
        OrderLogMapper.update(orderLog);
    }

    @Override
    public OrderLog queryById(int id) {
        OrderLog orderLog = OrderLogMapper.queryById(id);
        return orderLog;
    }

    /**
     * 插入多条订餐记录
     *
     * @param logList
     */
    @Override
    public void saveAll(List<OrderLog> logList) {
        orderLogRepository.saveAll(logList);
    }
}
